/*
 * Player.h
 *
 *  Created on: Oct 13, 2011
 *	Created by: Devin Manno
 *  Updated by: Devin Manno
 *	Last Update: Oct 27, 2011
 */

#ifndef PLAYER_H_
#define PLAYER_H_

#include "Character.h"
#include "PlayerStats.h"
#include "Potion.h"
#include <string>
#include <ctime>
#include <cstdlib>
#include <string.h>
#include <string>
#include <fstream>
#include <ostream>
#include <istream>
#include <iostream>
#include <sstream>


class Player: public Character {

private:
	PlayerStats playerStats;
	void setupPlayer();		// setup the rest of the player's members during player creation
	bool levelUp();
	enum unlockLevels {DEFAULT = 1, UNLOCK1 = 5,UNLOCK2 = 10,UNLOCK3 = 15,UNLOCK4 = 20}; // levels at which players unlock abilities
	void boostStats(unlockLevels); // boost stats according to level
	static const int XPFULL = 100;

public:
    Player():Character("Player"){}
	Player(string characterName, CharClass cClass, PlayerStats pStats) :    // controller class will generate new player, including name, class and player stats
	                Character(characterName, cClass, "Player"), playerStats(pStats) {

	                if(cClass == WIZARD)
	                        playerStats.setActionPointsType("Mana");
	                else
	                        playerStats.setActionPointsType("Endurance");
	                setupPlayer();
	        }

	virtual ~Player();

	// getters
	std::string getClassName() const;
	PlayerStats& getPlayerStats();		// return the player's stats

	// setters
	bool equip(EquipmentType* item, std::string &errorMsg);  	//  equip an equipmentType. returns true if successful; errorMsg = reason for failure.
	EquipmentType* dequip(EquipmentType* item, std::string &errorMsg);  	// dequip an equipmentType. returns true if successful; errorMsg = reason for failure.
	bool usePotion(Potion *potion);				// use a potion. returns true if successful.  controller should delete potion pointer on success.
	bool increaseExp(int);		// increase character experience points

	void regenerateHP();

	void regenerateAP();

    void savePlayer(string fileName)
    {
        ofstream out(fileName.c_str());
        if(out.is_open())
        {
            saveCharacter(out);
            out << playerStats;
        }
        else
        {
            string msg = "Error: The file " + fileName + " did not open for writing.";
            throw msg;
        }
        out.close();

    }

    void loadPlayer(string fileName)
    {
        ifstream in(fileName.c_str());
        if(in.is_open())
        {
            loadCharacter(in);
            in >> playerStats;
        }
        else
        {
            string msg = "Error: The file " + fileName + " did not open for reading.";
            throw msg;
        }
        in.close();
    }
};

#endif /* PLAYER_H_ */
